package com.glorystone.ins.handler;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.glorystone.ins.exception.ErrorMessage;
import com.glorystone.ins.exception.CreditException;

/**
 * @author liuming
 * @date 2017年11月6日 下午6:13:15
 */
@ControllerAdvice
public class CreditResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(value = {CreditException.class})
    protected ResponseEntity<Object> handleGenericException(final CreditException ex, final WebRequest request) {
	    final ErrorMessage errorMessage = new ErrorMessage(ex.getErrorCode(), ex.getMessage(), ex.getData());
        return new ResponseEntity<Object>(errorMessage, HttpStatus.BAD_REQUEST);
  }
}
